﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Infrastructure.Core;
using Domain.Core;
using Domain.Core.Repository;
using DDD_AOP_WCF.Domain;
using DDD_AOP_WCF.Infrastructure;
namespace 学习陈晴阳的DDD_AOP_WCF.Controllers
{
    public class UserController : Controller
    {

        backgroundEntities db = new DDD_AOP_WCF.Domain.backgroundEntities();
        IExtensionRepository<C_User_Info> iRepository;
        public UserController()
        {
            iRepository = new DbContextRepository<C_User_Info>(db);
        }
        //
        // GET: /User/

        public ActionResult Index(string userName, DateTime? startTime, DateTime? endTime, int? page)
        {
            var linq = iRepository.GetModel();

            if (!string.IsNullOrWhiteSpace(userName))
                linq = linq.Where(i => i.UserName == userName);
            if (startTime.HasValue && startTime != DateTime.MinValue)
                linq = linq.Where(i => i.RegisterTime >= startTime);
            if (endTime.HasValue && endTime != DateTime.MinValue)
                linq = linq.Where(i => i.RegisterTime <= endTime);

            var model = new PagedList<C_User_Info>(linq.OrderBy(i => i.UserID), page ?? 1, 10);
            if (Request.IsAjaxRequest())
                return PartialView(model);
            return View(model);
        }

    }
}
